<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>DataGrid Complex Toolbar - jQuery EasyUI Demo</title>
	<script type="text/javascript" src="__PUBLIC__/Resourse/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Resourse/js/jquery.cookie.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Resourse/themes/default/easyui.css" id="easyuiTheme">
	<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Resourse/js/changeEasyuiTheme.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Resourse/themes/icon.css">
	<script type="text/javascript" src="__PUBLIC__/Resourse/js/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="__PUBLIC__/Resourse/js/common.js"></script>	
	<style type="text/css">  
        #studentfm{  
            margin:0px 10px 0px 20px;  
            padding:10px 10px 25px 5px;  
       }  
       .ftitle{  
            font-size:14px;  
            font-weight:bold;  
            padding:5px 0;  
            margin-bottom:0px;  
            border-bottom:1px solid #ccc;  
        }  
       .fitem{  
            margin-bottom:5px;  
       }  
        .fitem label{  
           display:inline-block;  
           
        }
        .formText {
        	width : 150px;
        }  
        .file-box{ position:relative;width:340px} 
		.txt{ height:22px; border:1px solid #cdcdcd; width:180px;} 
		.btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;} 
		.file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px } 
		
    </style>  
    <script type="text/javascript">  
      var url; 
      
      //当前时间
      function getNowDate(){
          var curr_time = new Date();
          var strDate = curr_time.getFullYear()+"-";
          if(curr_time.getMonth()+1<10){
        	  strDate += "0"+(curr_time.getMonth()+1)+"-";
          }else{
        	  strDate += curr_time.getMonth()+1+"-";
          }      
          if(curr_time.getDate()<10){
        	  strDate += "0" + curr_time.getDate();
          }else{
        	  strDate += curr_time.getDate();
          }       
          return strDate;
      }
      
      //根据年级得到入学年份
      function getRXYear(nj){
    	  var curr_time = new Date();
    	  var year = curr_time.getFullYear();   	  
    	  if(nj!=0){
        	  return year - nj ;   		  
    	  }else{
    		  return year ;
    	  }
      }
      
      //初始化学生表单
      function initStuForm(){    	 
    	  $("#XS_CSRQ").datebox("setValue", getNowDate());
    	  $("input[name='XS_XB']").get(2).checked = true; 
    	  $('#XS_XX').combobox('setValue','0');
    	  $('#XS_XQ').combobox('setValue','0');
    	  $('#XS_TJR').combobox('setValue','0');
    	  $('#XS_FZR').combobox('setValue','0');
    	  $('#XS_NJ').combobox('setValue','nj1');
    	  $('#XS_BJ').combobox('setValue','bj1');
    	  $('#XS_RXRQ').val(getRXYear($('#XS_NJ').combobox('getValue').substr(-1,1))); 
      }
      
      
      function newUser(){  
            $('#dlg').dialog('open').dialog('setTitle','新增学生信息');  
           	$('#studentfm').form('clear'); 
           	initStuForm();
            url = '__URL__/add/';  
       }  
        
       function editUser(){  
    	   var rows = $('#stu_list_data').datagrid('getSelections'); 
            if (rows.length == 1){  
               $('#dlg').dialog('open').dialog('setTitle','修改学生信息');  
               $('#studentfm').form('load',rows[0]);  
               url = '__URL__/save?id=' + rows[0].Id;  
           }  
       }
       
       //根据条件查找
       function searchStu() {
    	   var xx_search = $("#XS_XX_SEARCH").combobox('getValue');
    	   var nj_search = $("#XS_NJ_SEARCH").combobox('getValue');
    	   var bj_search = $("#XS_BJ_SEARCH").combobox('getValue');
    	   
    	   var XS_XX = (xx_search==0)?null:xx_search;
    	   var XS_NJ = (nj_search==0)?null:nj_search;
    	   var XS_BJ = (bj_search==0)?null:bj_search;
 	
    	   var queryParams = $('#stu_list_data').datagrid('options').queryParams; 
    	   queryParams.XS_XX = XS_XX ;   
    	   queryParams.XS_NJ = XS_NJ ;   
    	   queryParams.XS_BJ = XS_BJ ;   
    	   
    	   $('#stu_list_data').datagrid('options').queryParams = queryParams; 
    	   $('#stu_list_data').datagrid('reload'); 
       }
     	
       //保存
       function saveUser(){
           $('#studentfm').form('submit',{  
                url: url,  
                onSubmit: function(){  
                   return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');  
                    if (result.errorMsg){  
                       $.messager.show({  
                           title: '错误',  
                           msg: result.errorMsg  
                        });  
                    } else {  
                        $('#dlg').dialog('close');      // close the dialog  
                        $('#stu_list_data').datagrid('reload');    // reload the user data  
                    }  
                }  
            });  
        }  
       
       //删除学生
        function destroyUser(){  
           var rows = $('#stu_list_data').datagrid('getSelections');  
           var ids = '';
           for(var i=0;i<rows.length;i++){
        	   ids += rows[i].Id + ',';
           }
           ids = ids.substring(0, ids.length-1);//获取所有要删除的ID
            if (rows.length!=0){  
            	$.messager.defaults.ok = "确定"; //改变默认按钮文字
            	$.messager.defaults.cancel = "取消"; //改变默认按钮文字
                $.messager.confirm('确认','确认要删除吗?',function(r){             	
                   if (r){              	   
                      $.post('__URL__/del/',{id:ids},function(result){  
                            if (result.success){  
                               $('#stu_list_data').datagrid('reload');    // reload the user data  
                            } else {  
                               $.messager.show({   // show error message  
                                    title: '错误',  
                                    msg: result.errorMsg  
                                });  
                           }  
                       },'json');  
                    }  
                });  
            }  
       }  
        
       $(window).resize(function(){  
        	$('#tt').datagrid('resize');  
       });   
       
       //设置分页
       $(function(){
           $("#stu_list_data").datagrid({
        	    onDblClickRow: function(rowIndex) {
        	    $("#stu_list_data").datagrid('selectRow',rowIndex);
        	     var currentRow = $('#stu_list_data').datagrid('getSelected'); 
        	     
                 $('#dlg').dialog('open').dialog('setTitle','学生信息');  
                 $('#studentfm').form('load',currentRow);  
                 //url = '__URL__/save?id=' + currentRow.Id;  
     			 disableForm('studentfm',true);//禁用表单
        	     }
           });
           
           //年级获取改变入学日期
           $('#XS_NJ').combobox({
        	   onChange: function (n,o) {
        		   $('#XS_RXRQ').val(getRXYear(n.substr(-1,1)));
        	   }
           });
           
    	 	//设置分页控件  
           var p = $('#stu_list_data').datagrid('getPager');  
           $(p).pagination({  
               pageSize: 20,//每页显示的记录条数，默认为10  
               pageList: [20,30,50,100],//可以设置每页记录条数的列表  
               beforePageText: '第',//页数文本框前显示的汉字  
               afterPageText: '页    共 {pages} 页',  
               displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',  
           });
        
       });
       
       //导入批量学生数据
       function import_check(){
    	    var f_content = upload_form.fileField.value;
    	    if(f_content==''){
    	               alert('请选择您要上传的文件！');
    	               return false;
    	    }
    	    var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.length)
    	        fileext=fileext.toLowerCase();
    	    if (fileext!='.xls') {
    	        alert("对不起，批量导入数据文件应为xls格式文件 ！");           
    	        return false;
    	    }
    	}
       
    </script>  
</head>
<body class="easyui-layout" style="border-width:50px;margin:0">
	<div id="mainPanle"  region="center"  border="false" >
	<table id ="stu_list_data" class="easyui-datagrid" style="margin:0"
			data-options="title:'学生信息列表',border:true,striped:true,nowrap:false,fit:true,autoRowHeight:false,rownumbers:true,pageSize:20,pagination:true,singleSelect:false,url:'__URL__/read/',toolbar:'#tb'" >
		<thead>
			<tr>
				<th data-options="field:'checkbox',checkbox:true" id="checkedAll"></th>	
				<th data-options="field:'Id',fitColumns: true,hidden:true">ID</th>
				<th data-options="field:'XS_XH',fitColumns: true,width:140,align:'center'">学号</th>
				<th data-options="field:'XS_XM',fitColumns: true,width:80,align:'center'">姓名</th>
				<th data-options="field:'XS_PY',fitColumns: true,width:80,align:'center'">拼音</th>
				<th data-options="field:'XS_XB',fitColumns: true,width:80,align:'center',formatter:function(value,rowData,rowIndex){ if(value == 'F'){ return '男'} else if(value =='M') { return '女'} else { return '保密'}}">性别</th>
				<th data-options="field:'XS_CSRQ',itColumns: true,width:120,align:'center'">出生日期</th>
				<th data-options="field:'XS_RXRQ',itColumns: true,width:120,align:'center'">入学年份</th>
				<th data-options="field:'XS_XX',itColumns: true,width:160,align:'center',hidden:true">就读学校</th>
				<th data-options="field:'XX',itColumns: true,width:160,align:'center'">就读学校</th>
				<th data-options="field:'XS_NJ',itColumns: true,width:80,align:'center',hidden:true">年级</th>
				<th data-options="field:'NJ',itColumns: true,width:80,align:'center'">年级</th>
				<th data-options="field:'XS_BJ',itColumns: true,width:80,align:'center',hidden:true">班级</th>
				<th data-options="field:'BJ',itColumns: true,width:80,align:'center'">班级</th>
				<th data-options="field:'XS_JZXM',itColumns: true,width:80,align:'center'">家长姓名</th>
				<th data-options="field:'XS_JZDH',itColumns: true,width:80,align:'center'">家长电话</th>
				<th data-options="field:'XS_JTZZ',itColumns: true,width:200,align:'center'">家庭住址</th>
				<th data-options="field:'XS_ZT',itColumns: true,width:80,align:'center',formatter:function(value,rowData,rowIndex){ if(value == 'xszt1'){ return '活跃'} else { return '冻结'}}">状态</th>
			</tr>
		</thead>
	</table>
	<div id="tb" style="padding:5px;height:auto">
		<!--  <div style="margin-bottom:0px">
		<table>
			<tr>
				<td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">添加</a>  </td>
				<td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改</a> </td>
				<td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">删除</a></td>
				<td><div class="file-box"> 
						<form id="upload_form" action="__URL__/uploadFile/" method="post" enctype="multipart/form-data"> 
						<input type='text' name='textfield' id='textfield' class='txt' /> 
						<input type='button' class='btn' value='浏览...' /> 
						<input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" /> 
						<input type="submit" name="submit" class="btn" value="批量导入" onclick="return import_check();"/> 
						</form>
					</div>  
				</td>
			</tr>  
			</table>
		</div>-->
		<div>
			<form id="stu_search_form" method="post" novalidate> 
			学校:<input name="XS_XX_SEARCH" id="XS_XX_SEARCH" class="easyui-combobox formText" style="width:150px" data-options="valueField:'ITEM_KEY',textField:'text',url:'__URL__/getDictList/type/XX'" >
			年级:<input name="XS_NJ_SEARCH" id="XS_NJ_SEARCH" class="easyui-combobox formText" style="width:150px" data-options="valueField:'ITEM_KEY',textField:'text',url:'__URL__/getDictList/type/JDNJ'" >
			班级:<input name="XS_BJ_SEARCH" id="XS_BJ_SEARCH" class="easyui-combobox formText" style="width:150px" data-options="valueField:'ITEM_KEY',textField:'text',url:'__URL__/getDictList/type/JDBJ'" >
			<a href="javascript:searchStu()" class="easyui-linkbutton" iconCls="icon-search">查询</a>
			</form>
		</div>
	</div></div>
	<div id="dlg" class="easyui-dialog" style="width:820px;height:450px;padding:5px"  
            closed="true" buttons="#dlg-buttons">  
        <div class="ftitle">学生基本信息</div>  
        <form id="studentfm" method="post" novalidate>  
            <!--  <div class="fitem">  
                <label>学&nbsp;&nbsp;&nbsp;&nbsp;号:</label>  
               <input name="XS_XH" class="easyui-validatebox formText" required>  
            </div>          -->
             <table cellspacing="10">
             	<tr>
             		<td>
             			<div class="fitem">  
			                <label>姓&nbsp;&nbsp;&nbsp;&nbsp;名:</label>  
			               <input name="XS_XM" class="easyui-validatebox formText"  required="true"  missingMessage="不能为空">  
			            </div>  
             		</td>
             		<td>
			            <div class="fitem">  
			                <label>性&nbsp;&nbsp;&nbsp;&nbsp;别:</label>  
			                <INPUT type="radio" name="XS_XB" value="F">男
							<INPUT type="radio" name="XS_XB" value="M">女
							<INPUT type="radio" name="XS_XB" value="O" checked="checked">保密
			           </div> 
             		</td>
              		<td>
			           <div class="fitem">  
			                <label>出生日期:</label>  
							<input name="XS_CSRQ" id="XS_CSRQ" class="easyui-datebox formText"></input>
			           </div>  
             		</td>            		
             	</tr>
             	<tr>	
             		<td>  
			           <div class="fitem">  
			                <label>所属校区:</label>  
							<input class="easyui-combobox formText" id="XS_XQ" name="XS_XQ" 
									data-options="valueField:'ITEM_KEY',textField:'text',url:'__URL__/getDictList/type/XQ'">
			           </div>  
			        </td>
			        <td>         
			           <div class="fitem">  
			                <label>就读学校:</label>  
							<input class="easyui-combobox formText" id="XS_XX" name="XS_XX" 
									data-options="valueField:'ITEM_KEY',textField:'text',url:'__URL__/getDictList/type/XX'">
			           </div>
             		</td>  
             		<td>
			           <div class="fitem">  
			                <label>就读年级:</label>  
							<input name="XS_NJ" ID="XS_NJ" class="easyui-combobox formText" 
							data-options="valueField:'ITEM_KEY',textField:'text',url:'__URL__/getDictList/type/JDNJ'" > 
			           </div>
			         </td>               	            		       		
             	</tr>
             	<tr>
             		<td>
			           <div class="fitem">  
			                <label>入学年份:</label>  
							<input name="XS_RXRQ" class="easyui-validatebox formText" id="XS_RXRQ" readonly="readonly"></input>
			           </div>
             		</td> 			         
			         <td>
			           <div class="fitem">  
			                <label>就读班级:</label>  
							<input name="XS_BJ" ID="XS_BJ" class="easyui-combobox formText" data-options="valueField:'ITEM_KEY',textField:'text',url:'__URL__/getDictList/type/JDBJ'"> 
			           </div>
             		</td>  
             		<td>
			           <div class="fitem">  
			                <label>家长姓名:</label>  
							<input name="XS_JZXM" id="XS_JZXM" class="easyui-validatebox formText"> 
			           </div>   
			         </td>             		        		
             	</tr>
             	<tr>
			         <td>
			           <div class="fitem">  
			                <label>家庭电话:</label>  
							<input name="XS_JTDH" id="XS_JTDH" class="easyui-validatebox formText" > 
			           </div>  
             		</td>  
             		<td>
			           <div class="fitem">  
			                <label>家长电话:</label>  
							<input name="XS_JZDH" id="XS_JZDH" class="easyui-validatebox formText" > 
			           </div>    
			         </td>
			         <td>
			            <div class="fitem">  
			                <label>家长邮箱:</label>  
			                <input name="XS_JZMAIL" id="XS_JZMAIL" class="easyui-validatebox formText" validType="email">  
			            </div>  
             		</td>               		        		
             	</tr>
             	<tr>
             		<td colspan="3">
			           <div class="fitem">  
			                <label>家庭住址:</label>  
							<input name="XS_JTZZ" id="XS_JTZZ" class="easyui-validatebox formText" style="width:600px" > 
			           </div>
             		</td>          		
             	</tr>
             	<tr>
             		<td>
			            <div class="fitem">
			                <label>负&nbsp;责&nbsp;人:</label>  
							<input  class="easyui-combobox formText"  data-options="valueField:'account',textField:'nickname',url:'__URL__/getTJR'"id="XS_FZR" name="XS_FZR">
			           </div>    
			         </td>
			         <td>
			            <div class="fitem">
			                <label>推&nbsp;荐&nbsp;人:</label>  
							<input  class="easyui-combobox formText"  data-options="valueField:'account',textField:'nickname',url:'__URL__/getTJR'" id="XS_TJR"  name="XS_TJR">
			           </div>  
             		</td>               		         		
             	</tr>   
             	<tr>
             		<td colspan="3">
			           <div class="fitem">
			                <label>备&nbsp;&nbsp;&nbsp;&nbsp;注:</label>
			                <input name="XS_BZ" class="easyui-validatebox formText"  style="width:600px"> 
			            </div>  
             		</td>           		
             	</tr>             	       	           	
             </table>

            <!--<div class="fitem">  
                <label>姓名拼音:</label>  
                <input name="XS_PY" class="easyui-validatebox formText" >  
            </div>-->
            <input name="XS_ZT" class="easyui-validatebox formText"  type="hidden">         
        </form>  
    </div>  
    <div id="dlg-buttons">  
       <!--   <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">保存</a>  -->
       <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
    </div>  
</body>
</html>